package com.example.mycontact.adapter

import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.example.mycontact.R
import com.example.mycontact.bean.Contact

class MyContactAdapter(var context: Activity,var contactList: ArrayList<Contact>): BaseAdapter() {
    override fun getCount(): Int {
        return contactList.size
    }

    override fun getItem(position: Int): Any {
        return contactList.get(position)
    }

    override fun getItemId(position: Int): Long {
        return contactList.get(position).id.toLong()
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        //加载显示的布局
        val view = LayoutInflater.from(context).inflate(R.layout.activity_main_list_item,null)
        val contact = contactList.get(position)
        val tv_name = view.findViewById<TextView>(R.id.list_item_tv_name)
        val tv_company = view.findViewById<TextView>(R.id.list_item_tv_company)
        val tv_position = view.findViewById<TextView>(R.id.list_item_tv_position)
        tv_name.setText(contact.name)
        tv_company.setText(contact.company)
        tv_position.setText(contact.position)

        return view
    }

}